package site.teamo.biu.net.client.controller;

import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import site.teamo.biu.net.client.controller.model.overview.HttpHttpsProxyServiceOverview;
import site.teamo.biu.net.client.core.http_https_proxy.HttpHttpsProxyService;
import site.teamo.biu.net.common.constant.ConnectionType;
import site.teamo.biu.net.client.core.http_https_proxy.TrafficStatistics;
import site.teamo.biu.tool.core.model.BiuJSONResult;
import site.teamo.biu.tool.core.util.BiuJSONResultUtils;

/**
 * @author haocongshun
 * @date 2023/06/07 16:35:39
 */
@RestController
@RequestMapping("/api/overview")
public class OverviewController {

    @Resource
    private HttpHttpsProxyService httpHttpsProxyService;

    @GetMapping("/http-https-proxy-service")
    public BiuJSONResult<HttpHttpsProxyServiceOverview> httpHttpsProxyServiceOverview() {
        HttpHttpsProxyServiceOverview httpHttpsProxyServiceOverview = new HttpHttpsProxyServiceOverview();
        //流量信息
        TrafficStatistics trafficStatistics = httpHttpsProxyService.getTrafficStatistics();
        httpHttpsProxyServiceOverview
                .setDirectTrafficIn(trafficStatistics.getDirectIn().get())
                .setDirectTrafficOut(trafficStatistics.getDirectOut().get())
                .setProxyTrafficIn(trafficStatistics.getProxyIn().get())
                .setProxyTrafficOut(trafficStatistics.getProxyOut().get());
        //连接信息
        httpHttpsProxyServiceOverview
                .setDirectConnectionNumber(httpHttpsProxyService.connectionState(ConnectionType.DIRECT).size())
                .setProxyConnectionNumber(httpHttpsProxyService.connectionState(ConnectionType.PROXY).size());
        httpHttpsProxyServiceOverview.setConnectionState(httpHttpsProxyService.connectionState(null));
        return BiuJSONResultUtils.ok(httpHttpsProxyServiceOverview);
    }

}
